package org.scohen.juploadr.uploadapi.zooomr;

import java.util.Collection;
import java.util.Iterator;

import org.scohen.juploadr.Messages;
import org.scohen.juploadr.app.UploadImage;
import org.scohen.juploadr.ui.Task;
import org.scohen.juploadr.uploadapi.zooomr.transform.Rotate;

public class RotateTask extends Task {
    private Collection images;
    private ZooomrRestApi api;
    private String photoName;
    private int cur;

    public RotateTask(Collection images, ZooomrRestApi api) {
        super();
        this.min = 0;
        this.max = images.size();
        this.images = images;
        this.api = api;
    }

    public String getTitle() {
        return Messages.getString("juploadr.ui.task.rotate.rotating.title", max); //$NON-NLS-1$ 
    }

    public void execute() {

        Iterator iter = images.iterator();
        while (iter.hasNext()) {

            UploadImage image = (UploadImage) iter.next();
            photoName = image.getTitle();
            updateProgress(++cur);
            Rotate rotate = new Rotate(image);
            api.executeMethod(rotate);

        }
    }

    public String getMessage() {
        return Messages.getString("juploadr.ui.task.rotate.rotating", photoName,cur,max); //$NON-NLS-1$ 
    }

}
